/**
 * Created by dqw on 2015/12/30.
 */

//列表开始
var cashstatus = {1: '待处理', 2: '待审核', 3: '待出账', 4: '提现成功', 5: "提现失败", 6: "提现取消"};
var dtGridColumns = [
    {
        id: 'delFlag',
        type: 'int',
        hideQuery:true,
        'export':false,
        hideQueryType:'eq',
        hideQueryValue:1,
        hide:true
    },
    // {
    //     id: 'id',
    //     title: '提款Id',
    //     type: 'number',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: true,
    //     fastQuery: true,
    //     fastQueryType: 'lk'
    // },
    {
        id: 'orderNo',
        title: '订单号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'u.userName',
        title: '用户名',
        type: 'string',
        headerClass: 'text-center ',
        columnClass: 'text-left ',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    // {
    //     id: 'u.mobile',
    //     title: '手机号',
    //     type: 'string',
    //     headerClass: 'text-center',
    //     columnClass: 'text-center',
    //     fastSort: false,
    //     fastQuery: true,
    //     fastQueryType: 'lk'
    // },
    {
        id: 'ui.realName',
        title: '真实姓名',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left ',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'bankName',
        title: '银行',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'bankNo',
        title: '银行卡号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk'
    },
    {
        id: 'branch',
        title: '支行',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: false,
        fastQueryType: 'range',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'amount',
        title: '提现金额',
        type: 'number',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: false
    },
    // {
    //     id: 'fee',
    //     title: '手续费',
    //     type: 'number',
    //     headerClass: 'text-center',
    //     columnClass: 'text-left',
    //     fastSort: false,
    //     fastQuery: false
    //
    // },
    {
        id: 'outOrderNo',
        title: '外部单号',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        fastQuery: true,
        fastQueryType: 'lk',
        hideType: 'md|sm|xs|lg'
    },
    {
        id: 'outStatus',
        title: '第三方返回状态',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        hideType: 'md|sm|xs|lg',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if(record.outStatus== undefined){
                return "--";
            }else{
                return record.outStatus;
            }
        }
    },
    {
        id: 'outMsg',
        title: '第三方返回消息',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        hideType: 'md|sm|xs|lg',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if(record.outMsg== undefined){
                return "--";
            }else{
                return record.outMsg;
            }
        }
    },
    {
        id: 'status',
        title: '状态',
        type: 'int',
        codeTable: cashstatus,
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'eq',
        codeTable: {
            1: $lang.cashStatus.T1,
            2: $lang.cashStatus.T2,
            3: $lang.cashStatus.T3,
            4: $lang.cashStatus.T4,
            5: $lang.cashStatus.T5,
            6: $lang.cashStatus.T6
        }
    },
    {
        id: 'remark',
        title: '备注',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: false,
        hideType: 'md|sm|xs|lg',
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if(record.remark== undefined){
                return "--";
            }else{
                return record.remark;
            }
        }
    },
    {
        id: 'createTime',
        title: '申请时间',
        type: 'date',
        format: 'yyyy-MM-dd hh:mm:ss',
        headerClass: 'text-center',
        columnClass: 'text-left',
        fastSort: true,
        fastQuery: true,
        fastQueryType: 'range'
    },
    {
        id: 'operation',
        title: '审核',
        type: 'string',
        headerClass: 'text-center',
        columnClass: 'text-center',
        fastSort: false,
        resolution: function (value, record, column, grid, dataNo, columnNo) {
            if (record.status == 2) {
                if ($("#cashAudit") && $("#cashAudit").val() == 1) {
                    return "<a data-target='#auditModal' class='btn btn-sm btn-primary m-r-10' data-toggle='modal' data-no='" + dataNo + "' ><i class='fa fa-edit'></i>&nbsp;审核&nbsp;</a>";
                }
            } else {
                return "";
            }
            return "";
        }
    }
];

var dtGridOption = {
    lang: 'zh-cn',
    ajaxLoad: true,
    loadURL: ncGlobal.adminRoot + 'cash/json/list',
    exportURL: ncGlobal.adminRoot + 'cash/json/export',
    exportFileName: '提现审核',
    columns: dtGridColumns,
    gridContainer: 'dtGridContainer',
    toolbarContainer: 'dtGridToolBarContainer',
    tools: 'refresh|faseQuery|export[excel]',
    pageSize: 10,
    pageSizeLimit: [10, 20, 50],
    ncColumnsType: {BigDecimal:["amount", "actualArrival",  "fee",  "feePlat"], int: ["status","delFlag"], Timestamp: ["createTime"]}
};

var grid = $.fn.DtGrid.init(dtGridOption);
grid.fastQueryParameters = new Object();
grid.fastQueryParameters['eq_delFlag'] = 1;

//排序
grid.sortParameter.columnId = ['asc_status','desc_createTime'];


//操作处理开始
var OperateHandle = function () {

    function _bindEvent() {

        //去除输入框回车键提交
        $("input").on("keydown", function (e) {
            if (e.keyCode == 13) {
                e.preventDefault();
                var a = $("#releasePrice");
                a.length && a.trigger("click");
            }
        });

        //审核对话框初始化
        $("#auditModal").on("show.bs.modal", function (event) {
            //清除错误信息
            $(".alert-danger").remove();
            $("#auditForm").psly().reset();
            //获取接受事件的元素
            var button = $(event.relatedTarget);
            //获取data 参数
            var data = grid.sortOriginalDatas[button.data('no')];

            var model = $(this);
            model.find('input[name="id"]').val(data.id);
            model.find('input[name="ui.realName"]').val(data.ui.realName);
            model.find('input[name="u.mobile"]').val(data.u.mobile);
            model.find('input[name="account"]').val(data.amount);
            // model.find('input[name="fee"]').val(data.fee);
            model.find('input[name="createTimeStr"]').val(data.createTime);
            model.find('input[name="actualArrival"]').val('');
            model.find('input[name="outOrderNo"]').val('');
            model.find('textarea[name="remark"]').val('');
            $(".status").bootstrapSwitch('state', true);
        });

        //模糊搜索
        $('#customSearch').click(function () {
            grid.fastQueryParameters = new Object();
            grid.fastQueryParameters['eq_delFlag'] = 1;
            grid.fastQueryParameters['lk_u.mobile_or_lk_u.user_name_or_lk_orderNo'] = $('#keyword').val();
            grid.pager.startRecord = 0;
            grid.pager.nowPage = 1;
            grid.pager.recordCount = -1;
            grid.pager.pageCount = -1;
            grid.refresh(true);
        });
    }

    /**
     * 提现取消
     */
    function cashCancle(id) {
        var tpl = '取消提现后将解冻用户提现的金额，您确定要取消该笔提现吗?'
        $.ncConfirm({
            url: ncGlobal.adminRoot + "cash/json/cancle",
            data: {
                id: id
            },
            content: tpl
        });
    }

    /**
     * 提现查询（查询第三方对账）
     */
    function cashQuery(id) {
        var tpl = '提现查询将查询该笔提现在第三方托管平台的提现状态，并进行处理，是否确定执行查询?'
        $.ncConfirm({
            url: ncGlobal.adminRoot + "cash/json/query",
            data: {
                id: id
            },
            content: tpl
        });
    }

    //外部可调用
    return {
        bindEvent: _bindEvent,
        cashCancle: cashCancle,
        cashQuery: cashQuery
    }

}();
//操作处理结束

$(function () {
    //加载列表
    grid.load();
    //页面绑定事件
    OperateHandle.bindEvent();
});